const app = getApp();
Page({
    /**
     * 页面的初始数据
     */
    data: {
        showtype: 'zqlq',
        arrData: [],
        tabs: ["全部", "营销系统", "家居建材", "美妆护肤", "数码电器", "母婴玩具", "零元购活动",],
        winHeight: "",//窗口高度
        winWidth:'',//
        currentTab: 0, //预设当前项的值
        scrollLeft:0, //tab标题的滚动条位置
    },
    // 滚动切换标签样式
    switchTab: function (e) {
        this.setData({
            currentTab: e.detail.current
        });
        this.checkCor();
    },
    // 点击标题切换当前页时改变样式
    swichNav: function (e) {
        var cur = e.target.dataset.current;
        var offsetLeft=e.target.offsetLeft;
        console.log(offsetLeft);
        //var scrollLeft=(cur+1)*52;
        console.log(cur);
        //console.log(this.data.winWidth);
        // var width = this.data.winWidth/5
        if (this.data.currentTab == cur) { return false; }
        else {
            this.setData({
                currentTab: cur,
            //    scrollLeft: offsetLeft
            })
        }
    },
    //判断当前滚动超过一屏时，设置tab标题滚动条。
    checkCor: function () {
        if (this.data.currentTab > 4) {
            this.setData({
                scrollLeft: 300
            })
        } else {
            this.setData({
                scrollLeft: 0
            })
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that=this;
        console.log('category onLoad', options)
        wx.getSystemInfo({
            success: function (res) {
                console.log(res);
                var clientHeight = res.windowHeight,
                    clientWidth = res.windowWidth,
                    rpxR = 750 / clientWidth;
                var calc = clientHeight * rpxR - 180;
                that.setData({
                    winHeight: calc,
                   winWidth:clientWidth
                });
            }
        });
        // 模拟加载数据，根据不同的showtype去后台加载不同的数据
        this.setData({
            arrData: [
                {
                    icon: 'https://cdn.jxb001.net/img-prize/201709/20170912182416293493.jpg',
                    price: 149,
                    title: '小米（MI）小米手环2代 只能运动手环',
                    detailUrl: '/page/shop/detail/index?id=1'
                }, {
                    icon: 'https://cdn.jxb001.net/img-prize/201709/20170927141115750082.jpg',
                    price: 2499,
                    title: '小米Note3 全网通 6GB+64GB 黑色 移动联通电信4G',
                    detailUrl: '/page/shop/detail/index?id=2'
                }, {
                    icon: 'https://cdn.jxb001.net/img-prize/201709/20170912173343144283.jpg',
                    price: 298,
                    title: '阿迪达斯（ADIDAS） 欧冠男子场上训练比赛用球',
                    detailUrl: '/page/shop/detail/index?id=3'
                }, {
                    icon: 'https://cdn.jxb001.net/img-prize/201707/20170718175204615033.jpg',
                    price: 399,
                    title: 'RAX户外徒步鞋登山鞋',
                    detailUrl: '/page/shop/detail/index?id=4'
                }, {
                    icon: 'https://cdn.jxb001.net/img-prize/201709/20170922111656137865.jpg',
                    price: 898,
                    title: '蓝堡动感单车 家用室内静音健身车D700 黑蓝色',
                    detailUrl: '/page/shop/detail/index?id=5'
                },
                {
                    icon: 'https://cdn.jxb001.net/img-prize/201709/20170922111656137865.jpg',
                    price: 898,
                    title: '蓝堡动感单车 家用室内静音健身车D700 黑蓝色',
                    detailUrl: '/page/shop/detail/index?id=5'
                },
                {
                    icon: 'https://cdn.jxb001.net/img-prize/201709/20170922111656137865.jpg',
                    price: 898,
                    title: '蓝堡动感单车 家用室内静音健身车D700 黑蓝色',
                    detailUrl: '/page/shop/detail/index?id=5'
                },
                {
                    icon: 'https://cdn.jxb001.net/img-prize/201709/20170922111656137865.jpg',
                    price: 898,
                    title: '蓝堡动感单车 家用室内静音健身车D700 黑蓝色',
                    detailUrl: '/page/shop/detail/index?id=5'
                },
                {
                    icon: 'https://cdn.jxb001.net/img-prize/201709/20170912182416293493.jpg',
                    price: 149,
                    title: '小米（MI）小米手环2代 只能运动手环',
                    detailUrl: '/page/shop/detail/index?id=1'
                }, {
                    icon: 'https://cdn.jxb001.net/img-prize/201709/20170927141115750082.jpg',
                    price: 2499,
                    title: '小米Note3 全网通 6GB+64GB 黑色 移动联通电信4G',
                    detailUrl: '/page/shop/detail/index?id=2'
                }, {
                    icon: 'https://cdn.jxb001.net/img-prize/201709/20170912173343144283.jpg',
                    price: 298,
                    title: '阿迪达斯（ADIDAS） 欧冠男子场上训练比赛用球',
                    detailUrl: '/page/shop/detail/index?id=3'
                }, {
                    icon: 'https://cdn.jxb001.net/img-prize/201707/20170718175204615033.jpg',
                    price: 399,
                    title: 'RAX户外徒步鞋登山鞋',
                    detailUrl: '/page/shop/detail/index?id=4'
                }, {
                    icon: 'https://cdn.jxb001.net/img-prize/201709/20170922111656137865.jpg',
                    price: 898,
                    title: '蓝堡动感单车 家用室内静音健身车D700 黑蓝色',
                    detailUrl: '/page/shop/detail/index?id=5'
                },
                {
                    icon: 'https://cdn.jxb001.net/img-prize/201709/20170922111656137865.jpg',
                    price: 898,
                    title: '蓝堡动感单车 家用室内静音健身车D700 黑蓝色',
                    detailUrl: '/page/shop/detail/index?id=5'
                },
                {
                    icon: 'https://cdn.jxb001.net/img-prize/201709/20170922111656137865.jpg',
                    price: 898,
                    title: '蓝堡动感单车 家用室内静音健身车D700 黑蓝色',
                    detailUrl: '/page/shop/detail/index?id=5'
                },
                {
                    icon: 'https://cdn.jxb001.net/img-prize/201709/20170922111656137865.jpg',
                    price: 898,
                    title: '蓝堡动感单车 家用室内静音健身车D700 黑蓝色',
                    detailUrl: '/page/shop/detail/index?id=5'
                },
                {
                    icon: 'https://cdn.jxb001.net/img-prize/201709/20170922111656137865.jpg',
                    price: 898,
                    title: '蓝堡动感单车 家用室内静音健身车D700 黑蓝色',
                    detailUrl: '/page/shop/detail/index?id=5'
                },
                {
                    icon: 'https://cdn.jxb001.net/img-prize/201709/20170922111656137865.jpg',
                    price: 898,
                    title: '蓝堡动感单车 家用室内静音健身车D700 黑蓝色',
                    detailUrl: '/page/shop/detail/index?id=5'
                },
                {
                    icon: 'https://cdn.jxb001.net/img-prize/201709/20170922111656137865.jpg',
                    price: 898,
                    title: '蓝堡动感单车 家用室内静音健身车D700 黑蓝色',
                    detailUrl: '/page/shop/detail/index?id=5'
                }

            ]
        });
        // console.log(this.data.arrData.length);
        // let len=(this.data.arrData.length)*100;
        // this.setData({winHeight:len});
        

    },
    footerTap: app.footerTap,
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
       
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {
       
    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {
       
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
       
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
       
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        
    }
})